package leetcode.ge100;

import java.util.ArrayList;
import java.util.List;

class Solution_148 {

	class ListNode {
		int val;
		ListNode next;

		ListNode(int x) {
			val = x;
		}
	}

	public static void main(String[] args) {
	}

	private static List<Integer> list = new ArrayList<Integer>();

	public ListNode sortList(ListNode head) {

		while (head != null) {
			list.add(head.val);
			head = head.next;
		}

		list.sort(null);

		ListNode node = new ListNode(list.get(0));

		ListNode now = node;

		int l = list.size();
		for (int i = 1; i < l; i++) {
			now.next = new ListNode(list.get(i));
			now = now.next;
		}

		return node;

	}

}
